import java.io.FileInputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;

import io.minio.ObjectStat;
import org.xmlpull.v1.XmlPullParserException;

import io.minio.MinioClient;
import io.minio.errors.MinioException;

public class FileUploader {
    public static void main(String[] args) throws NoSuchAlgorithmException, IOException, InvalidKeyException, XmlPullParserException {
        try {
            // Create a minioClient with the Minio Server name, Port, Access key and Secret key.
            //MinioClient minioClient = new MinioClient("http://localhost:9000", "D5NKSY2IJSS78RCA8HGB", "nbkgRiWcbOBjtvwvu9pTi66E4JDVh8NEtEhsV6gt");
            MinioClient minioClient=new MinioClient("http://192.168.100.198:9000 ", "0RXUGTZPDN4LYJ6GL1IV", "L81oc5LpYXbK9hKxXK6kra7oW3izSIedjidX6hBI");
            // Check if the bucket already exists.
            boolean isExist = minioClient.bucketExists("asiatrip");
            if(isExist) {
                System.out.println("Bucket already exists.");
            } else {
                // Make a new bucket called asiatrip to hold a zip file of photos.
                minioClient.makeBucket("asiatrip");
            }

            // Upload the zip file to the bucket with putObject
            /*
            minioClient.putObject("asiatrip","asiaphotos.zip", "C:\\Users\\Max Woods\\Pictures\\Saved Pictures\\snap002.png");
            System.out.println("/home/user/Photos/asiaphotos.zip is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.");
            ObjectStat stat= minioClient.statObject("asiatrip","asiaphotos.zip");
            System.out.println(stat.toString());
            String url=minioClient.getObjectUrl("asiatrip","asiaphotos.zip");
            System.out.println(url);
            */
            String fileName="snap002.png";
            FileInputStream fis=new FileInputStream( "C:\\Users\\Max Woods\\Pictures\\Saved Pictures\\snap002.png");
            minioClient.putObject("asiatrip",fileName,fis,fis.available(),"application/octet-stream");
            String url=minioClient.getObjectUrl("asiatrip",fileName);
            System.out.println(url);
        } catch(MinioException e) {
            System.out.println("Error occurred: " + e);
        }
    }
}
